home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / BBS / MUBBS / MUBBS etc.cpt / Module Source / Files Module / Files Module Main.c < prev    next >
Text File  |  1991-11-22  |  25KB  |  871 lines

  1. /*
  2.  *  Files Module Main.c
  3.  *
  4.  *    This program source code and it's compiled version is
  5.  *  Copyright (c) 1991 N. Hawthorn.
  6.  *  This program source code and it's compiled version IS NOT IN THE
  7.  *  PUBLIC DOMAIN ! Please read the "COPYRIGHT NOTICE / NH" file for details
  8.  *  regarding use of this program source code and it's compiled version.
  9.  *
  10.  *  This module's name is "files", it's type is "MOD1", use a resource mover
  11.  *  to assign a new number to it, that's why we name our modules !
  12.  *
  13.  *  This is where it all starts...
  14.  *
  15.  */
  16.  
  17. #define INMAIN
  18.  
  19. #include <SetUpA4.h>
  20. #include "MUBBS Module.h"
  21.  
  22. struct PPP {
  23.             char filename[256]; /* the whole file and folder name */
  24.             char justname[64]; /* just the file name (for the user to see) */
  25.             long size; /* the size of a file either received or sent */
  26.             int mode; /* the mode send, receive */
  27.             int result;   /* the result of the transfer */
  28.             char reserved[32]; /* some extra bytes for future use  */
  29.             };
  30.  
  31.  
  32. #define    RECEIVE        0    /* Receive a file */
  33. #define    SEND        1    /* Send a file */
  34.  
  35. #define    ABORT        1    /* Return ERROR */
  36. #define    NOTFOUND    2    /* Return ERROR */
  37. #define    NOCREATE    3    /* Return ERROR */
  38.  
  39. #define MAX_DESC_LINES  3
  40. #define MAX_DESC_CHAR 80
  41. #define CHARSPERFILE 308
  42. #define MAXFILETRIES 10
  43.  
  44. /* my globals for this file */
  45.  
  46.  
  47.  
  48. pascal void main (mode1,G1,P) /* called from the main routines, and what mode to be in */
  49. int mode1;
  50. struct GS *G1; /* we point to the "global" struct in the Main Module here */
  51. Ptr P; /* we ignore this pointer, we do not use it at all */
  52. {
  53. Handle temph;
  54. float version = 0.5; /* what version of MUBBS you are compatable with IE: .5 and above */
  55. RememberA0(); SetUpA4(); /* This sets up the A4 register to access our globals */
  56. asm { _RecoverHandle }; asm {move.l a0,temph}; HLock(temph); /* locks our module, do this ! */
  57.  
  58. G=G1; /* This MUST be the first thing you do in main only, it sets up the struct globals */
  59. mode[u]=mode1; /* set up our mode so that you can read it anywhere */
  60.  
  61. switch (mode[u]) { /* any un-handled modes return error from this module */
  62.     case 2:
  63.         doit();
  64.         G->moduleresult=0;
  65.         break;
  66.     case 98:
  67.         versionck(version); /* just return after this call, don't modify anything */
  68.         break;        
  69.     case 0:
  70.         strcpy (G->programmer,"N Hawthorn"); /* show the programmer's name up to 20 chars*/
  71.         G->moduleresult=0; /* this was also a init call if we need close call put 99 here */
  72.         break;
  73.     default:
  74.         G->moduleresult=1; /* return bad code */
  75.     };
  76.  
  77. HUnlock(temph); /* unlocks this module, do this ! */
  78. RestoreA4(); /* call this when you are all done */
  79. }
  80.  
  81.  
  82. doit(){
  83. char temp[31], folder[256], dirfile[256], blank[31], tempstring[256];
  84. int a,b,x,t,chars,type;
  85. FILE *stream;
  86.  
  87. if (!G->online[u]) goto done; /* do this check so we can log out if hang up */
  88.  
  89. loguser("In Files Module"); /* this tells where you are for remote sysop, or writes to log file */
  90.  
  91. /* you print the following so that the sysop can monitor use on the mac screen */
  92.  
  93. print("C> Line %d %s, at: Files\n",(u+1),G->username[u]);
  94.  
  95. G->okcancel[u]=TRUE;
  96. G->nocheck[u]=FALSE; /* check for controls */
  97. G->cancel[u]=FALSE;
  98. sendtext(":files:fileintro.txt");
  99. strcpy(folder,":files"); /* start with the files folder */
  100. a=TRUE;
  101. while(a){
  102.  
  103.     strcpy(dirfile,folder);
  104.     strcat(dirfile,":directory");
  105.     if ((stream = fopen(dirfile, "r")) == NULL) {
  106.         print("FILE ERROR - cannot open %s\n",dirfile);
  107.         send("]FILE ERROR - Cannot open a directory file]");
  108.         return FALSE;
  109.         }
  110.     else print("directory %s\n",dirfile);
  111.  
  112.     fscanf(stream,"%10[^\n]\n",temp); /* find out what type it is */
  113.     type=strtoint(temp);
  114.     if(type <=2) { /* it's a folder directory */
  115.         b=TRUE;
  116.         while (b){
  117.             if (type ==2){ /* if it's type 2, generate your own menu */
  118.                 strcpy(tempstring,folder);
  119.                 strcat(tempstring,":filemenu");
  120.                 if (G->language[u] == 1)
  121.                     strcat(tempstring,".ansi");
  122.                 else
  123.                     strcat(tempstring,".txt");
  124.                 G->okcancel[u]=TRUE;
  125.                 G->nocheck[u]=FALSE; /* check for controls */
  126.                 G->cancel[u]=FALSE;
  127.                 sendtext(tempstring);
  128.                 }
  129.             else {
  130.                 send("]   *** File Menu ***]]>> ");
  131.                 x=FALSE; /* make a menu */
  132.                 chars=0;
  133.                 fseek(stream,0,0); /* start at the beginning of the file again */
  134.                 fscanf(stream,"%30[^\n]\n",blank); /* take out the directory type, if EOF it will get it later */
  135.                 while (fscanf(stream,"%30[^\n]\n",temp) != EOF){ /* get all chars */
  136.                     temp[16]= '\0'; /* limit the display to 15 chars */
  137.                     if (chars >  60) { /* if another name won't fit on screen */
  138.                         send("]>> "); /* send a CR */
  139.                         chars=0; /* show new line */
  140.                         x=FALSE; /* for new line */
  141.                         }
  142.                     if (x) {
  143.                         send (", ");
  144.                         chars++; /* account for the , */
  145.                         chars++;
  146.                         }
  147.                     for (t=0; temp[t] != 0; t++) { /* un scramble it */
  148.                         if (temp[t] != ':') G->out(temp[t]); /* don't print the ":" */
  149.                         chars++; /* count the characters outputed so far */
  150.                         }
  151.                     x=TRUE;
  152.                     }
  153.                 if (chars >  50) send("]>> "); /* send a CR */
  154.                 else send (", Help, Logoff, Quit ");
  155.                 }
  156.  
  157.             if (!(cmd1(":"))) {
  158.                 fclose(stream);
  159.                 goto done;
  160.                 }
  161.             send(G->CR[u]);
  162.             if(G->input[u] == 'Q') {
  163.                 if (!backup(folder)){ /* are we all the way back? */
  164.                     a=FALSE;
  165.                     b=FALSE; /* kill everything and quit out */
  166.                     break;
  167.                     }
  168.                 b=FALSE; /* try a new folder */
  169.                 break;
  170.                 }
  171.             if(G->input[u] == 'L') {
  172.                 G->online[u]=FALSE;
  173.                 a=FALSE;
  174.                 b=FALSE; /* log off, kill everything */
  175.                 break;
  176.                 }
  177.             if(G->input[u] == 'H') {
  178.                 G->okcancel[u]=TRUE;
  179.                 G->nocheck[u]=FALSE; /* check for controls */
  180.                 G->cancel[u]=FALSE;
  181.                 sendtext(":files:filehelp1.txt");
  182.                 continue;
  183.                 }
  184.             fseek(stream,0,0); /* start at the beginning of the file again */
  185.             fscanf(stream,"%30[^\n]\n",blank); /* take out the directory type, if EOF it will get it later */
  186.             while (fscanf(stream,"%30[^\n]\n",temp) != EOF){ /* go through all the choices */
  187.                 if (toupper(temp[1]) == G->input[u]){ /* do we have a FIRST character match ? */
  188.                     strcat(folder,temp); /* make a new "folder" string */
  189.                     b=FALSE; /* don't do the menu again */
  190.                     break;
  191.                     }
  192.                 }
  193.             } /* closes the while (b) */
  194.         } /* closes the "if type=" */
  195.     fclose(stream); /* close the file, it's not needed anymore */
  196.     if(type ==3) { /* it's a folder directory */
  197.         fileget(folder); /* show the file list, let them get a file */
  198.         if (!backup(folder)){ /* are we all the way back? */
  199.             a=FALSE;
  200.             break;
  201.             }
  202.         }
  203.     } /* closes the while (a) */
  204. done:
  205. return;
  206. }
  207.  
  208.  
  209. fileenter(folder)
  210. char *folder;
  211. {
  212. char     fname[65], sizes[12], by[26], extra1[7], deslens[7], des[227],temp[65];
  213. char    uploadfile[70], datetime[25];
  214. int        bad, index, index2, err, tries;
  215. unsigned long deslen;
  216. FILE *stream, *stream2;
  217. int oldrefnum, newrefnum, i;
  218. struct PPP P;
  219.  
  220. bad = FALSE;
  221. if (strcmp(G->userbaud[u],"300") == 0) {
  222.     send("]Users logged in at 300 baud are not allowed to upload/download here.]");
  223.     return;
  224.     }
  225. send("]]Your uploads are greatly appreciated by all !]");
  226.  
  227. poop:
  228. if (G->local[u]) {
  229.     send ("]Can't UPLOAD on LOCAL !]");
  230.     goto bb; /* cancel pressed */
  231.     }
  232. send("]Input filename for upload (24 characters MAX) :");
  233. portsin(fname, 24);
  234. if (! G->online[u]) goto bb; /* portsin returns online for a time out */
  235. send(G->CR[u]);
  236. if (strlen(fname) < 1) { send ("]Upload canceled.]"); goto bb; }
  237. if (strlen(fname) < 4) {send ("]Please use a more descriptive filename.]"); goto poop;}
  238. if (strchr(fname, '*')) bad = TRUE; /* returns TRUE if it's "*" */
  239. if (strchr(fname, ':')) bad = TRUE; /* returns TRUE if it's ":" */
  240. if (strchr(fname, '\\')) bad = TRUE; /* returns TRUE if it's "\" */
  241. if (strchr(fname, '~')) bad = TRUE; /* returns TRUE if it's "~" */
  242. strcpy(temp,fname);
  243. strtoupper(temp);
  244. if(strcmp(temp,"SYSOP") == 0) bad = TRUE; /* returns TRUE if it's a bad name */
  245. if(strcmp(temp,"SYSTEM") == 0) bad = TRUE;
  246. if(strcmp(temp,"FINDER") == 0) bad = TRUE; /* we DON'T want people to upload over this stuff !! */
  247. if(strcmp(temp,"DIRECTORY") == 0) bad = TRUE;
  248. if(strcmp(temp,"FILEINTRO.TXT") == 0) bad = TRUE;
  249. if(strcmp(temp,"FILEHELP1.TXT") == 0) bad = TRUE;
  250. if(strcmp(temp,"FILEHELP2.TXT") == 0) bad = TRUE;
  251. if(strcmp(temp,"FILEMENU.TXT") == 0) bad = TRUE;
  252. if(strcmp(temp,"FILEMENU.ANSI") == 0) bad = TRUE;
  253. if (bad) {
  254.     send("]Illegal character in filename or illegal filename!]");
  255.     return;
  256.     }
  257. strcpy(uploadfile, folder); /* folder can be up to 40 characters */
  258. strcat(uploadfile, ":");
  259. strcat(uploadfile, fname);
  260.  
  261. print("C> checking for existing file to upload %s\n",uploadfile);
  262. if ((stream = fopen(uploadfile, "r")) != NULL) { /* see if we can read it */
  263.     send("]That file name already exists !]Please check the list for this section !]");
  264.     fclose(stream);
  265.     goto bb;
  266.     }
  267. print("C> NEW FILE! allowing upload of %s\n",uploadfile);
  268.  
  269. if ( ! enterdesc(fname,des)) goto bb; /* get the description lines */
  270.  
  271. choice:
  272.     send("]Upload choices, please select one]");
  273.     if (!(cmd1("]Xmodem, Quit :"))) goto bb; /* timeout */
  274.     send(G->CR[u]);
  275.     switch (G->input[u]) {
  276.         case ('X'):
  277.             send ("]Ready to upload file \"");
  278.             send (fname);
  279.             send ("\"]");
  280.             print("\nUpload Whole filename =%s ",uploadfile);
  281.             goto getit;
  282.             break;
  283.         case ('Q'):
  284.             send ("]Upload canceled.]");
  285.             goto bb;
  286.             break;
  287.         default:
  288.             goto choice;
  289.         }
  290.  
  291. getit:
  292.  
  293.     if (!filereceive(uploadfile,fname,&P)) { /* get the file, delete it if transfer bad */
  294.         remove(uploadfile);
  295.         goto bb;
  296.         }
  297.  
  298. strcpy(uploadfile,folder); /* use "uploadfile"'s string space again */
  299. strcat(uploadfile,":directory");
  300. gettime("%m/%d/%y",datetime); /* gets the date in m/d/y */
  301. strcpy(by,G->username[u]);
  302. if ((P.size=P.size/1000)<1) P.size=1;
  303. longtostr(P.size,sizes); /* do a conversion first */
  304. strcpy(extra1,"");
  305. deslen = strlen(des);
  306. longtostr(deslen,deslens);
  307.  
  308. tries = 0;
  309. bsylp:
  310. if ((stream = fopen(uploadfile, "a")) == NULL) { /* now write it to the directory */
  311.     if (++tries < MAXFILETRIES) {
  312.         send("]FILE LIST FILE BUSY, PLEASE STANDBY");
  313.         wait(1); /* wait just a bit */
  314.         goto bsylp;
  315.         }
  316.     print("FILE ERROR - cannot open %s\n",uploadfile);
  317.     send("]FILE ERROR - Can't open the file list file !]");
  318.     send("]YOUR FILE MAY NOT APPEAR IN THE LIST, NOTIFY A SYSOP !!]");
  319.     }
  320. else {
  321.     print("update to directory %s\n",uploadfile); /* not really the upload file, the directory ! */
  322.  
  323.     if (fprintf(stream,"%-24s~%-10s~%-8s~%-24s~%-5s~%-5s~%-225s~",
  324.             fname,   /* the file name */
  325.             sizes,   /* size of the file */
  326.             datetime,    /* date uploaded */
  327.             by,      /* by who */
  328.             extra1,  /* extra data */
  329.             deslens, /* length of the description in bytes, the description to 225 bytes */
  330.             des ) == EOF) print("bad fprintf conversion\n");
  331.     }
  332. fclose(stream);
  333.  
  334. tries=0;
  335. bsylp1:
  336. if ((stream = fopen(":logs:uploadlog", "a")) == NULL) {
  337.     if (++tries < MAXFILETRIES) {
  338.         send("]PLEASE STANDBY...");
  339.         wait(1); /* wait just a bit */
  340.         goto bsylp1;
  341.         }
  342.     print("FILE ERROR - cannot open uploadlog\n");
  343.     send("]FILE ERROR - Can't open/create upload log file!]");
  344.     }
  345. else {
  346.     if (fprintf(stream, "%s %s UPLOADED \"%s\" %s %sK\n", datetime, by, fname, folder, sizes) < 0) {
  347.         send("]FILE ERROR - Upload log file file has problem writing]");
  348.         }
  349.     } 
  350. fclose(stream);
  351. send("]File list has been updated]");
  352.  
  353. bb:
  354. bad=0;
  355. }
  356.  
  357. enterdesc(fname,des)        /* enter the description */
  358. char *fname,*des;
  359. {
  360. char    text[5][MAX_DESC_CHAR + 3],lineshow[90];
  361. int        editmode;
  362.  
  363. strcpy(lineshow,"   ---------1---------2---------3---------4---------5---------6---------7---------8");
  364. strcpy(text[0],"\0");
  365. strcpy(text[1],"\0");
  366. strcpy(text[2],"\0"); /* clear these guys out */
  367. strcpy(text[3],"\0");
  368. editmode=FALSE;
  369.  
  370. getline0:
  371. send("]Please describe the file \"%s\" so others can identify it.]]",fname);
  372. send("   YOU CAN ENTER 2 FULL LINES OF DESCRIPTION AND 1 KEYWORD LIST]]");
  373.  
  374. send("The first line is the \"short\" description that is seen most often.]");
  375. send("To cancel the upload, enter a carriage return on an empty line.]]");
  376. send("%.*s!]01:",(33),lineshow); /* show 30 chars max */
  377. portsin(text[0], 30);
  378. if (! G->online[u]) goto byebye; /* returns online for a time out */
  379. if (strlen(text[0]) == 0) goto cancel;
  380. if (strlen(text[0]) < 10) {
  381.     send("]]You can describe it better than that, please try again...]");
  382.     goto getline0;
  383.     }
  384. strcat(text[0]," "); /* always add a space here */
  385. send(G->CR[u]);
  386. if (editmode) goto edit;
  387.  
  388. getline1:
  389. send("]The second line is the REST of line 1's description seen on full length lists]");
  390. send("(space already added). To leave blank, enter a carriage return on an empty line.]]");
  391. send("%.*s!]02:",(47),lineshow); /* show 44 chars max */
  392. portsin(text[1], 44);
  393. if (! G->online[u]) goto byebye; /* returns online for a time out */
  394. send(G->CR[u]);
  395. if (editmode) goto edit;
  396. if (strlen(text[1]) == 0) goto getkeys;
  397.  
  398. getline2:
  399. send("]The third line is the extended description seen on extended length lists.]");
  400. send("To leave blank, enter a carriage return on an empty line.]]");
  401. send("%.*s!]03:",(78),lineshow); /* show 75 chars max */
  402. portsin(text[2], 75);
  403. if (! G->online[u]) goto byebye; /* returns online for a time out */
  404. send(G->CR[u]);
  405. if (editmode) goto edit;
  406.  
  407. getkeys:
  408. send("]Please enter some KEYWORDS that will help in finding this file during a search.]");
  409. send("Put a space between words. EXAMPLE: processing word graphics business]");
  410. send("To end or if you have none, enter a carriage return on an empty line.]]");
  411. send("%.*s!] K:",(68),lineshow); /* show 65 chars max */
  412. portsin(text[3], 65);
  413. if (! G->online[u]) goto byebye; /* returns online for a time out */
  414. send(G->CR[u]);
  415. if (editmode) goto edit;
  416.  
  417. tryagain:
  418. if (!(cmd1("]Edit, List, Save, Quit :"))) goto byebye;
  419. send(G->CR[u]);
  420.  
  421. switch (G->input[u]) {    /* get 1 byte */
  422.     case ('E'):    /* edit message */
  423.         goto edit;
  424.         break;
  425.     case ('L'):    /* list message */
  426.         send("]]01=%s]",text[0]);
  427.         send("02=%s]",text[1]);
  428.         send("03=%s]",text[2]);
  429.         send("KEYWORDS=%s]]",text[3]);
  430.         break;
  431.     case ('S'):    /* save description */
  432.         strcpy(des,text[0]);
  433.         if (strlen(text[1]) >0) strcat(des,text[1]);
  434.         strcat(des,"\x0A"); /* add a end of line */
  435.         if (strlen(text[2]) >0) strcat(des,text[2]);
  436.         strcat(des,"\x0A"); /* add a end of line */
  437.         if (strlen(text[3]) >0) strcat(des,text[3]);
  438.         strcat(des,"\x0A"); /* add a end of line */
  439.         return TRUE;
  440.         break;
  441.     case ('Q'):    /* get out w/out saving */
  442.         if (!(cmd1("]Are you sure you want to QUIT ? (Y/N) :"))) goto byebye;
  443.         if (G->input[u] == 'Y') goto cancel;
  444.         goto tryagain;
  445.         break;
  446.     }
  447. goto tryagain;
  448.  
  449. edit:
  450. send("]Which line to edit (Quit goes back to the \"Edit\" menu) ?]");
  451. if (!(cmd1("1, 2, 3, K, List, Quit :"))) goto byebye;
  452. send(G->CR[u]);
  453. switch (G->input[u]) {    /* get 1 byte */
  454.     case ('1'):    /* edit message */
  455.         editmode = TRUE;
  456.         goto getline0;
  457.         break;
  458.     case ('2'):    /* edit message */
  459.         editmode = TRUE;
  460.         goto getline1;
  461.         break;
  462.     case ('3'):    /* edit message */
  463.         editmode = TRUE;
  464.         goto getline2;
  465.         break;
  466.     case ('K'):    /* edit message */
  467.         editmode = TRUE;
  468.         goto getkeys;
  469.         break;
  470.     case ('L'):    /* list message */
  471.         send("]]01=%s]",text[0]);
  472.         send("02=%s]",text[1]);
  473.         send("03=%s]",text[2]);
  474.         send("KEYWORDS=%s]]",text[3]);
  475.         break;
  476.     case ('Q'):    /* edit message */
  477.         goto tryagain;
  478.         break;
  479.     }
  480. goto edit;
  481.  
  482. cancel:
  483. send("]]Upload canceled]]");
  484. return FALSE;
  485.  
  486. byebye:
  487. G->online[u]=FALSE; /* show we timed out */
  488. return FALSE;
  489. }
  490.  
  491.  
  492. backup(folder) /* backs up to the first found ":" */
  493. char *folder;
  494. {
  495. int len;
  496. len = strlen(folder) - 1;
  497. while ((folder[len] != ':') && (len > 0)){
  498.     folder[len] = '\0';
  499.     len--;
  500.     }
  501. folder[len] = '\0'; /* take out the ":" */
  502. if (len==0) return FALSE;
  503. return TRUE;
  504. }
  505.  
  506.  
  507. fileget(folder)
  508. char *folder;
  509. {
  510. /* set this to the size of a whole entry in the dir plus the ~ characters*/
  511. char line1[227], dirfile[70];
  512. char fname[27], sizes[13], by[27], extra1[8], deslens[8], des[228], blank[31];
  513. char datetime[26], temp[65];
  514. int count, lines, marked, marked1, page, err, tries, got, empty;
  515. long int seek,startfile,endfile,wherewewere, size;
  516. unsigned long deslen;
  517. char filepick[11][28];
  518. char filemark[11][28];
  519. int downflag[11];
  520. FILE *stream;
  521. struct PPP P;
  522.  
  523. strcpy(dirfile,folder);
  524. strcat(dirfile,":directory");
  525. print("directory %s\n",dirfile);
  526. if ((stream = fopen(dirfile, "r")) == NULL) {
  527.     print("FILE ERROR - cannot open %s\n",dirfile);
  528.     send("]FILE ERROR - Cannot open file list file]");
  529.     return FALSE;
  530.     }
  531. page=1;
  532. marked=0;
  533. empty=FALSE;
  534. fscanf(stream,"%30[^\n]\n",blank); /* take out the directory type, if EOF it will get it later */
  535. if(feof(stream)) {
  536.     fclose(stream);
  537.     send("]]This file section is empty. You can UPLOAD here by selecting \"U\".]");
  538.     empty=TRUE;
  539.     goto loop;
  540.     }
  541. startfile=ftell(stream);
  542. if(err=fseek(stream,0,2) != 0) print("Fseek to end failed\n"); /* go to end of file */
  543. endfile=ftell(stream);
  544. seek=endfile-CHARSPERFILE; /* back up one record */
  545. fclose(stream);
  546. send("]New files are displayed first.");
  547.  
  548. next:
  549. if ((stream = fopen(dirfile, "r")) == NULL) { /* only leave it open shortly */
  550.     print("FILE ERROR - cannot open %s\n",dirfile);
  551.     send("]FILE ERROR - Cannot open file list file]");
  552.     return FALSE;
  553.     }
  554. lines=0;
  555. if (!G->cancel[u] && !empty) send("]]Page %d  FILENAME            SIZE (K)   DATE     UPLOADED BY]",page);
  556. G->linecnt[u]=1; /* start as if it's a new page ! (with one line already here) */
  557.  
  558. if(err=fseek(stream,seek,0) != 0) print("Fseek failed\n");
  559. while (got=fscanf(stream,"%26[^~]~%12[^~]~%25[^~]~%26[^~]~%7[^~]~%7[^~]~%227[^~]~",
  560.         fname,
  561.         sizes,
  562.         datetime,
  563.         by,
  564.         extra1,
  565.         deslens,
  566.         des)) {
  567.         if (got != 7) { /* 7 items should have been read here*/
  568.             send("]]ERROR found in this file directory, TELL A SYSOP !!]");
  569.             break;
  570.             }
  571.         seek=seek-CHARSPERFILE;
  572.         P.size = strtolong(sizes); /* do a conversion */
  573.         deslen = strtolong(deslens);
  574.         strcpy(filepick[lines],fname); /* save the file name for picking it out */
  575.  
  576.     if (!G->cancel[u])    {
  577.         send("%d> %s %s %s %s] ",lines,fname,sizes,datetime,by);        
  578.         if (G->cancel[u]) goto canceled;
  579.         count=0;
  580.         strncpy(line1,des,(deslen+1)); /* move the whole description over */
  581.         line1[deslen] = 0; /* make sure its terminated, the array starts at 0, remember that*/
  582.         while ((line1[count] != '\n') && (line1[count] != '\0') && (count <76) && (!G->cancel[u])) {
  583.             G->out(line1[count]); /* only print up to 75 of the characters */ 
  584.             count++;
  585.             }
  586.         if (!G->cancel[u]) send(G->CR[u]);
  587.         }
  588.     canceled:
  589.     lines++;
  590.     if(lines >9) break;
  591.     if(seek < startfile) break;
  592.     if(err=fseek(stream,seek,0) != 0) print("Fseek failed\n");
  593.     }
  594. fclose(stream);
  595.  
  596. loop:
  597. if (!(cmd1("]>> # to mark, Marked, Next, Prev, Options, Upload, Help, Quit (CR = next) : "))) goto done;
  598. send(G->CR[u]);
  599. if(empty) {
  600.     switch (G->input[u]) {
  601.         case 'U':
  602.         fileenter(folder); /* allow them to upload */
  603.         goto alldone;
  604.         break;
  605.         case 'Q':
  606.         goto done;
  607.         break;
  608.         }
  609.     goto loop;
  610.     }
  611.  
  612. if (G->input[u] >= '0' && G->input[u] <= (lines+0x2F)) {
  613.     if (marked>9) {
  614.         send ("]You have 10 files already marked, please press \"Q\" to download them.]");
  615.         goto loop;
  616.         }
  617.     G->input[u] = G->input[u]-0x30; /* make it a number */
  618.     send ("]File added to your list (marked #%d) :",(marked+1));
  619.     send (filepick[G->input[u]]);
  620.     strcpy(filemark[marked],filepick[G->input[u]]);
  621.     downflag[marked]=FALSE; /* show that it's not been downloaded yet */
  622.     send (G->CR[u]);
  623.     marked++;
  624.     goto loop;
  625.     }
  626. switch (G->input[u]) {
  627.     case 'H':
  628.     G->okcancel[u]=TRUE;
  629.     G->nocheck[u]=FALSE; /* check for controls */
  630.     G->cancel[u]=FALSE;
  631.     sendtext (":files:filehelp1.txt");
  632.     if (!G->online[u]) goto done;
  633.     break;
  634.     case 'N':
  635.     case '\x0d':
  636.     if (lines<10 || (seek <= startfile)){ send("]At last page.]"); goto loop; }
  637.     page++;
  638.     goto next;
  639.     break;
  640.     case 'P':
  641.     wherewewere=seek;
  642.     seek=seek+(CHARSPERFILE*lines);
  643.     seek=seek+(CHARSPERFILE*10);
  644.     if (seek > (endfile-CHARSPERFILE)){
  645.         seek=wherewewere; /* keep it at start */
  646.         send("]At First page.]"); goto loop;
  647.         }
  648.     if (--page < 1) page=1;
  649.     goto next;
  650.     break;
  651.     case 'O':
  652.     if (options(folder,line1)){ /* if we have a good name */
  653.         removespaces(line1); /* takes out trailing spaces */
  654.         strcpy(dirfile,folder);
  655.         strcat(dirfile, ":");
  656.         strcat(dirfile,line1);
  657.         if (filesend(dirfile,line1,&P)) { /* send the file, if bad skip log file*/
  658.             if ((P.size=P.size/1000)<1) P.size=1;
  659.             size=P.size;
  660.             logit(folder,line1,size);
  661.             }
  662.         }
  663.     break;
  664.     case 'U':
  665.     fileenter(folder); /* allow them to upload */
  666.     goto alldone;
  667.     break;
  668.     case 'Q':
  669.     goto done;
  670.     break;
  671.     case 'M':
  672.     marked1=0;
  673.     if (marked == 0) {
  674.         send ("]You have no files marked]");
  675.         break;
  676.         }
  677.     send ("]Files marked for download :]]");
  678.     while (marked1 < marked) {
  679.         strcpy(line1,filemark[marked1]);
  680.         removespaces(line1); /* takes out trailing spaces */
  681.         send ("#%d \"%s\"]",(marked1+1),line1);
  682.         marked1++;
  683.         }
  684.     send (G->CR[u]);
  685.     break;
  686.     }
  687. goto loop;
  688.  
  689. done:
  690.  
  691. marked1=0;
  692. if (marked == 0) {
  693.     send ("]You have no files marked, returning to menu..]");
  694.     goto alldone;
  695.         }
  696. marked--;
  697. next1:
  698. strcpy(line1,filemark[marked1]);
  699. removespaces(line1); /* takes out trailing spaces */
  700. send ("]File ready for download is #%d \"%s\"",(marked1+1),line1);
  701. if (downflag[marked1]) send (" << Successfully downloaded, select next.");
  702. if (!(cmd1("]] Download, Next, Prev, Help, Quit (return = next) :"))) goto byebye;
  703. send(G->CR[u]);
  704. switch (G->input[u]) {
  705.     case 'H':
  706.     G->okcancel[u]=TRUE;
  707.     G->nocheck[u]=FALSE; /* check for controls */
  708.     G->cancel[u]=FALSE;
  709.     sendtext (":files:filehelp2.txt");
  710.     if (!G->online[u]) goto byebye;
  711.     break;
  712.     case 'N':
  713.     case '\x0d':
  714.     if (marked1 < marked) marked1++;
  715.     else send("]You are at the last file in the list. Use Quit to end.]");
  716.     goto next1;
  717.     break;
  718.     case 'P':
  719.     if (marked1 > 0) marked1--;
  720.     else send("]You are at the FIRST file in the list.]");
  721.     goto next1;
  722.     break;
  723.     case 'D':
  724.     if (downflag[marked1]) {
  725.         send ("]]>> You already downloaded this file, are you sure you]");
  726.         if (!(cmd1("   want to try again (Y/N) ? "))) goto byebye;
  727.         send(G->CR[u]);
  728.         if (G->input[u] == 'Y') goto down;
  729.         }
  730.     else goto down;
  731.     break;
  732.     case 'Q':
  733.     goto alldone;
  734.     break;
  735.     }
  736. goto next1;
  737.  
  738. down:
  739. strcpy(dirfile,folder);
  740. strcat(dirfile, ":");
  741. strcat(dirfile,line1);
  742. if (!filesend(dirfile,line1,&P)) { /* send the file, if bad skip log file*/
  743.     goto next1;
  744.     }
  745.  
  746. downflag[marked1]=TRUE; /* mark the file as downloaded */
  747. if ((P.size=P.size/1000)<1) P.size=1;
  748. size=P.size;
  749. logit(folder,line1,size);
  750.  
  751. goto next1;
  752.  
  753. byebye:
  754. fclose(stream);
  755. G->online[u]=FALSE; /* show we timed out */
  756. return;
  757.  
  758. alldone:
  759. return;
  760. }
  761.  
  762. logit(folder,line1,size)
  763. char *folder, *line1;
  764. long size;
  765. {
  766. char datetime[26];
  767. int tries;
  768. FILE *stream;
  769.  
  770. getdatetime(datetime); /* gets the date & time */
  771.  
  772. tries = 0;
  773. bsylp:
  774. if ((stream = fopen(":logs:downloadlog", "a")) == NULL) {
  775.     if (++tries < MAXFILETRIES) {
  776.         send("]PLEASE STANDBY...");
  777.         wait(1); /* wait just a bit */
  778.         goto bsylp;
  779.         }
  780.     print("\nFILE ERROR - cannot open downloadlog ");
  781.     send("]FILE ERROR - Can't open/create download log file!]");
  782.     }
  783. else {
  784.     if (fprintf(stream, "%s %s DOWNLOADED \"%s\" %s %ldK\n", datetime, G->username[u], line1, folder, size) < 0) {
  785.         send("]FILE ERROR - Download log file file has problem writing]");
  786.         }
  787.     } 
  788. fclose(stream);
  789. }
  790.  
  791. options(folder,temp)
  792. char *folder;
  793. char *temp;
  794. {
  795. char fname[33];
  796. int bad;
  797.  
  798. bad=FALSE;
  799. send("]   *** Options Menu ***]");
  800. send("]Input the EXACT filename to download (32 characters MAX) :");
  801. portsin(fname, 32);
  802. if (! G->online[u]) return FALSE; /* portsin returns online for a time out */
  803. send(G->CR[u]);
  804. if (strlen(fname) < 1) { send ("]Download canceled.]"); return FALSE; }
  805. if (strchr(fname, '*')) bad = TRUE; /* returns TRUE if it's "*" */
  806. if (strchr(fname, ':')) bad = TRUE; /* returns TRUE if it's ":" */
  807. if (strchr(fname, '\\')) bad = TRUE; /* returns TRUE if it's "\" */
  808. if (strchr(fname, '~')) bad = TRUE; /* returns TRUE if it's "~" */
  809. strcpy(temp,fname);
  810. strtoupper(temp);
  811. if(strcmp(temp,"SYSOP") == 0) bad = TRUE; /* returns TRUE if it's a bad name */
  812. if(strcmp(temp,"SYSTEM") == 0) bad = TRUE;
  813. if(strcmp(temp,"FINDER") == 0) bad = TRUE; /* we DON'T want people to download this stuff !! */
  814. if(strcmp(temp,"DIRECTORY") == 0) bad = TRUE;
  815. if(strcmp(temp,"FILEINTRO.TXT") == 0) bad = TRUE;
  816. if(strcmp(temp,"FILEHELP1.TXT") == 0) bad = TRUE;
  817. if(strcmp(temp,"FILEHELP2.TXT") == 0) bad = TRUE;
  818. if(strcmp(temp,"FILEMENU.TXT") == 0) bad = TRUE;
  819. if(strcmp(temp,"FILEMENU.ANSI") == 0) bad = TRUE;
  820. if (bad) {
  821.     send("]Illegal character in filename or illegal filename!]");
  822.     return FALSE;
  823.     }
  824.  
  825. return TRUE;
  826. }
  827.  
  828. filesend(name,justname,P)
  829. char *name, *justname;
  830. struct PPP *P;
  831. {
  832. if (strcmp(G->userbaud[u],"300") == 0) {
  833.     send("]Sorry, users logged in at 300 baud are not allowed to upload/download here.]");
  834.     return FALSE;
  835.     }
  836. strcpy(P->filename,name);
  837. strcpy(P->justname,justname);
  838. P->mode= SEND;
  839. P->result= 9;
  840. module(3,"XFER_Xmodem",P);
  841. if (P->result ==0) {
  842.     send("]File transfered OK]");
  843.     return TRUE;
  844.     }
  845. else {
  846.     send("]Some type of error sending file %d]",P->result);
  847.     return FALSE;
  848.     }
  849. }
  850.  
  851. filereceive(name,justname,P)
  852. char *name, *justname;
  853. struct PPP *P;
  854. {
  855. strcpy(P->filename,name);
  856. strcpy(P->justname,justname);
  857. P->mode= RECEIVE;
  858. P->result= 9;
  859. module(3,"XFER_Xmodem",P);
  860.  
  861. if (P->result ==0) {
  862.     send("]File transfered OK]");
  863.     return TRUE;
  864.     }
  865. else {
  866.     send("]Some type of error receiving file %d]",P->result);
  867.     return FALSE;
  868.     }
  869. }
  870.  
  871.